import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routes'

//进度条
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
NProgress.configure({ showSpinner: false }); //取消进度条加载时转圈的效果

Vue.use(VueRouter)


const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})


//全局前置守卫   
router.beforeEach((to,from,next)=>{
    NProgress.start() //进度条动画开始
    document.title = to.meta && to.meta.title || '饿了么'; //注意：如果meta为空的话，会返回undefined,用||''   就是解决这个问题的
    next();//放行
})
//全局后置守卫
router.afterEach((to,from)=>{
    NProgress.done(); //进度条动画结束
})

export default router

